use anyhow::{Error, Result, format_err};
use serde::{Deserialize, Serialize};
use validator::Validate;
use uuid::Uuid;

#[derive(Serialize, Deserialize, Validate, PartialEq, Debug)]
struct ProxyRuleYaml {
    action: String,
    dest: String,
    to: Option<Uuid>,
}

#[derive(Serialize, Deserialize, Validate, PartialEq, Debug)]
struct Socks5Yaml {
    enable: bool,
    port: Option<u16>,
    proxy_rule: Option<Vec<ProxyRuleYaml>>,
}

#[derive(Serialize, Deserialize, Validate, PartialEq, Debug)]
struct RedirRuleYaml {
    local_port: u16,
    uuid: Uuid,
    redir_addr: String,
}

#[derive(Serialize, Deserialize, Validate, PartialEq, Debug)]
struct RedirYaml {
    enable: bool,
    redir_rules: Option<Vec<RedirRuleYaml>>,
}

#[derive(Serialize, Deserialize, Validate, PartialEq, Debug)]
struct Config {
    ca_base64: String,
    cert_base64: String,
    key_base64: String,
    proxy_addr: String,
    socks5: Option<Socks5Yaml>,
    redir: Option<RedirYaml>,
}

// pub fn parse_config(cfg_path: &str) -> Result<Config, Error> {
//     let cfg_str = include_str!(cfg_path);
//     let cfg = serde_yaml::from_str::<Config>(cfg_str)?;
//     Err(format_err!("Configuration error"))
// }

#[test]
fn test_parse_config() {
    let cfg_str = include_str!("./config.yaml");
    let cfg_yaml = serde_yaml::from_str::<Config>(cfg_str).unwrap();
    println!("{:#?}", cfg_yaml);
}
